'user strict'
import React, {
    Component
} from 'react'
import {
    hashHistory
} from 'react-router'

import '../../Scss/header'

export default class Header extends Component {
    constructor(props) {
        super(props)
    }
    componentWillMount() {
        //跳转关闭提示
        if (document.querySelector('.tips')) {
            document.querySelector('.tips').style.display = 'none'
        }
    }
    goBlack() {
        //执行新方法
        if (this.props.addFn) {
            this.props.addFn();
            return;
        }

        //执行新跳转
        if (this.props.newLink) {
            hashHistory.push(this.props.toLink);
            return;
        }
        if (this.props.outLink) {
            location.href = this.props.outLink
            return;
        }
        hashHistory.goBack(-1);
    }
    render() {
        const {
            title,
            link,
            back
        } = this.props;
        return (
            <header className="header">
                {back
                    ? back
                    : <a className="h_back" onClick={this.goBlack.bind(this)}></a>}
                <label className="h_title">
                    {title
                        ? title
                        : this.props.children}
                </label>
                {link
                    ? link
                    : ''}
            </header>
        )
    }
}
